import "package:flutter/material.dart";

// https://github.com/dooboolab/flutter_calendar_carousel
import './classes/event.dart';
import './classes/event_list.dart';
import './flutter_calendar_carousel.dart';   // 实例 0 参考

class CalendarPage3 extends StatefulWidget {
    final String text;
    
    CalendarPage3({Key key, this.text}) : super(key: key);
    
    @override
    _CalendarPage3State createState() => _CalendarPage3State();
}

class _CalendarPage3State extends State<CalendarPage3> {
    
    DateTime _currentDate = DateTime(2019, 8, 3);
    DateTime _currentDate2 = DateTime(2019, 8, 3);
    String _currentMonth = '';

//  List<DateTime> _markedDate = [DateTime(2018, 9, 20), DateTime(2018, 10, 11)];
    static Widget _eventIcon = new Container(
        decoration: new BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.all(Radius.circular(1000)),
            border: Border.all(color: Colors.blue, width: 2.0)),
        child: new Icon(
            Icons.person,
            color: Colors.amber,
        ),
    );
    
    EventList<Event> _markedDateMap = new EventList<Event>(
        events: {
            new DateTime(2019, 8, 10): [
                new Event(
                    date: new DateTime(2019, 8, 10),
                    title: 'Event 1',
                    icon: _eventIcon,
                ),
                new Event(
                    date: new DateTime(2019, 8, 10),
                    title: 'Event 2',
                    icon: _eventIcon,
                ),
                new Event(
                    date: new DateTime(2019, 8, 10),
                    title: 'Event 3',
                    icon: _eventIcon,
                ),
            ],
        },
    );
    
    @override
    Widget build(BuildContext context) {
        return Scaffold(
            appBar: PreferredSize(
                preferredSize: Size.fromHeight(36.0),
                child: AppBar(
                    centerTitle: true,
                    elevation: 0.5,
                    titleSpacing: 0.0,
                    title: Text(widget.text),
                ),
            ),
            body: CalendarCarousel<Event>(
                onDayPressed: (DateTime date, List<Event> events) {
                    this.setState(() => _currentDate = date);
                    events.forEach((event) => print(event.title));
                },
                weekendTextStyle: TextStyle(
                    color: Colors.red,
                ),
                thisMonthDayBorderColor: Colors.grey,
                // weekDays: null, /// for pass null when you do not want to render weekDays
                headerText: Container(
                    
                    /// Example for rendering custom header
                    child: Text('Custom Header'),
                ),
                // markedDates: _markedDate,
                staticSixWeekFormat:false,
                weekFormat: false,
                markedDatesMap: _markedDateMap,
                height: double.infinity,
                selectedDateTime: _currentDate2,
                // daysHaveCircularBorder: false, /// null for not rendering any border, true for circular border, false for rectangular border
                customGridViewPhysics: NeverScrollableScrollPhysics(),
                markedDateShowIcon: true,
                markedDateIconMaxShown: 2,
                todayTextStyle: TextStyle(
                    color: Colors.blue,
                ),
                markedDateIconBuilder: (event) {
                    return event.icon;
                },
                onCalendarChanged: (date) {
                    print('onCalendarChanged : $date');
                },
                todayBorderColor: Colors.green,
                markedDateMoreShowTotal: false, // null for not showing hidden events indicator
                // markedDateIconMargin: 9,
                // markedDateIconOffset: 3,
            ),
        );
    }
}

